deferred class CD_CANVAS_GENERAL_ATTRIBUTES
-- Predefined values of colors:
--
-- cd_red          = (255,  0,  0)
-- cd_dark_red     = (128,  0,  0)
-- cd_green        = (0  ,255,  0)
-- cd_dark_green   = (  0,128,  0)
-- cd_blue         = (  0,  0,255)
-- cd_dark_blue    = (  0,  0,128)
-- cd_yellow       = (255,255,  0)
-- cd_dark_yellow  = (128,128,  0)
-- cd_magenta      = (255,  0,255)
-- cd_dark_magenta = (128,  0,128)
-- cd_cyan         = (  0,255,255)
-- cd_dark_cyan    = (  0,128,128)
-- cd_white        = (255,255,255)
-- cd_black        = (  0,  0 , 0)
-- cd_dark_gray    = (128,128,128)
-- cd_gray         = (192,192,192)

inherit
	CANVAS_DRAW

feature {ANY}

	-- Color features

	set_foreground_color (red, green, blue: INTEGER)
		-- Configures a new current foreground rgb color. This color is used in 
		-- all primitives (lines, areas, marks and text). Default value: black.
		local
			i: INTEGER
		do
			i := int_canvas_foreground (cnvs, encode_color(red, green, blue))
		end

	set_foreground_color_alpha (red, green, blue, alpha: INTEGER)
		-- Configures a new current foreground color with alpha (rgba). This 
		-- color is used in all primitives (lines, areas, marks and text). 
		-- Default value: black.
		local
			i: INTEGER
		do
			i := int_canvas_foreground (cnvs, encode_color(red, green, blue))
		end

	set_predefined_foreground_color (color: INTEGER)
		-- Set a predefined foreground rgb color. The predefined values are:
		--
		-- cd_red, cd_dark_red, cd_green, cd_dark_green, cd_blue, cd_dark_blue,
		--	cd_yellow, cd_dark_yellow, cd_magenta, cd_dark_magenta, cd_cyan,
		--	cd_dark_cyan, cd_white, cd_black, cd_dark_gray, cd_gray.
		--
		-- Default value: cd_black
		local
			i: INTEGER
		do
			i := int_canvas_foreground (cnvs, color)
		end

	get_foreground_color: TUPLE[INTEGER, INTEGER, INTEGER]
		-- Return the rgb values of the current foreground color.
		local
			i: INTEGER
		do
			i := int_canvas_foreground (cnvs, -1)

			Result := decode_color (i)
		end

	get_foreground_color_alpha: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
		-- Return the rgba values of the current foreground color.
		local
			i: INTEGER
		do
			i := int_canvas_foreground (cnvs, -1)

			Result := decode_color_alpha (i)
		end

	set_background_color (red, green, blue: INTEGER)
		-- Configures a new current background rgb color. However, it does not 
		-- automatically change the background of a canvas. For such, it is 
		-- necessary to call the "clear" function. The background color only 
		-- makes sense for "clear" and for primitives affected by the background 
		-- opacity attribute. Default value: white.
		local
			i: INTEGER
		do
			i := int_canvas_background (cnvs, encode_color(red, green, blue))
		end

	set_background_color_alpha (red, green, blue, alpha: INTEGER)
		-- Configures a new current background rgba color. However, it does not 
		-- automatically change the background of a canvas. For such, it is 
		-- necessary to call the "clear" function. The background color only 
		-- makes sense for "clear" and for primitives affected by the background 
		-- opacity attribute. Default value: white.
		local
			i: INTEGER
		do
			i := int_canvas_background (cnvs, encode_color(red, green, blue))
		end

	set_predefined_background_color (color: INTEGER)
		-- Set a predefined background rgb color. The predefined values are:
		--
		-- cd_red, cd_dark_red, cd_green, cd_dark_green, cd_blue, cd_dark_blue,
		--	cd_yellow, cd_dark_yellow, cd_magenta, cd_dark_magenta, cd_cyan,
		--	cd_dark_cyan, cd_white, cd_black, cd_dark_gray, cd_gray.
		--
		-- However, it does not automatically change the background of a canvas. 
		-- For such, it is necessary to call the "clear" function. The background 
		-- color only  makes sense for "clear" and for primitives affected by the 
		-- background opacity attribute.
		--
		-- Default value: cd_black
		local
			i: INTEGER
		do
			i := int_canvas_background (cnvs, color)
		end

	get_background_color: TUPLE[INTEGER, INTEGER, INTEGER]
		-- Return the rgb values of the current background color.
		local
			i: INTEGER
		do
			i := int_canvas_background (cnvs, -1)

			Result := decode_color (i)
		end

	get_background_color_alpha: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
		-- Return the rgba values of the current background color.
		local
			i: INTEGER
		do
			i := int_canvas_background (cnvs, -1)

			Result := decode_color_alpha (i)
		end

	-- Write mode features

	set_write_mode_replace
		-- Set the replace writing type for all drawing primitives. This is the 
		-- default value.
		local
			i: INTEGER
		do
			i := int_canvas_write_mode (cnvs, 0)
		end

	set_write_mode_xor
		-- Set the xor writing type for all drawing primitives.
		--
		-- Note: operation XOR is very useful, because, using white as the 
		-- foreground color and drawing the same image twice, you can go back to 
		-- the original color, before the drawing. This is commonly used for 
		-- mouse selection feedback.
		local
			i: INTEGER
		do
			i := int_canvas_write_mode (cnvs, 1)
		end

	set_write_mode_not_xor
		-- Set the not xor writing type for all drawing primitives.
		local
			i: INTEGER
		do
			i := int_canvas_write_mode (cnvs, 2)
		end

	get_write_mode: STRING
		-- Return the current write type. Possible values: CD_REPLACE, CD_XOR or 
		-- CD_NOT_XOR.	
		local
			i: INTEGER
		do
			i := int_canvas_write_mode (cnvs, -1)

			if i.is_equal(2) then
				Result := "CD_NOT_XOR"
			elseif i.is_equal(1) then
				Result := "CD_XOR"
			else
				Result := "CD_REPLACE"
			end
		end

feature {NONE}

	-- Internals

	int_canvas_foreground (wgt: POINTER; cl: INTEGER): INTEGER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return cdCanvasForeground ($wgt, $cl);"
      end

	int_canvas_background (wgt: POINTER; cl: INTEGER): INTEGER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return cdCanvasBackground ($wgt, $cl);"
      end

	int_canvas_write_mode (wgt: POINTER; mode: INTEGER): INTEGER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return cdCanvasWriteMode ($wgt, $mode);"
      end

end

-- The MIT License (MIT)

-- Copyright (c) 2016, 2019 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
